<?php

class APPCore_Form_Decorator_Description extends Zend_Form_Decorator_Abstract
{
    /**
     * Render html of element after decorator
     *
     * @param string $content
     * @return string
     */
    public function render($content)
    {
        if (null === ($element = $this->getElement())) {
            return $content;
        }

        if (!method_exists($element, 'getLabel')) {
            return $content;
        }

        $element->setDecorators(array(
            'ViewHelper',
            'Description',
            'Errors',
        ));

        $description = '<tr><td id="' . $element->getAttrib('id') . '-element" colspan="3">
            <div' . $this->_createAttribs($element->getAttribs()) . ' >' . $element->getLabel() . '</div></td></tr>';

        return $description;
    }

    /**
     * Create attributes for description
     *
     * @param array $attribs
     * @return string
     */
    private function _createAttribs($attribs)
    {
        //init array atribute need add to label
        $arrAttrHtml = array('id', 'class', 'style');

        $attribHtml = '';
        foreach ($arrAttrHtml as $attrHtmlKey) {
            if (isset($attribs[$attrHtmlKey])) {
                $attribHtml .= ' ' . $attrHtmlKey . '="' . $attribs[$attrHtmlKey] . '"';
            }
        }
        return $attribHtml;
    }

}